#include <bits/stdc++.h>

#define VNAME(name) (#name)
#define debug(x) {auto debugx = x; std::cout << " (" << VNAME(x) << ": " << (debugx) << ") ";}
#define debugln(x) {auto debugx = x; std::cout << " (" << VNAME(x) << ": " << (debugx) << ")" << std::endl;}
#define F_(n) cout << fixed << setprecision(n)
using namespace std;
const int N = 1e6;
typedef long long LL;
typedef pair<LL, LL> PLL;
LL arr[N];
inline LL X(LL l, LL r) {
    return r * N + l;
}
unordered_map<LL, bool> M;
signed main() {
    int n, k;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n >> k;
    for (int i = 1; i <= n; ++ i) {
        cin >> arr[i], arr[i] += arr[i - 1];
    }
    priority_queue<PLL, vector<PLL>, less<PLL> > q;
    q.push({arr[n], X(1, n)}); M[X(1, n)] = true;
    while (k --) {
        cout << q.top().first << ' ';
        int l = q.top().second % N, r = q.top().second / N;
        q.pop();
        if (l == r) continue;
        if (!M[X(l + 1, r)]) M[X(l + 1, r)] = true, q.push({arr[r] - arr[l], X(l + 1, r)});
        if (!M[X(l, r - 1)]) M[X(l, r - 1)] = true, q.push({arr[r - 1] - arr[l - 1], X(l, r - 1)});
        //debug(l); debugln(r);
    }
    cout << endl;
    return 0;
}